use sea_orm::ActiveModelTrait;
use sea_orm_practice::User;
use sea_orm_practice::user;
use sea_orm::EntityTrait;
use sea_orm::Database;
use sea_orm::ActiveValue::Set;
use sea_orm::ColumnTrait;
use sea_orm::EntityOrSelect;
use sea_orm::QueryFilter;

//sea-orm-cli generate entity -u mysql://root:123456@localhost/sea-orm-practice -s public -o out

#[tokio::main]
async fn main() {
    println!("Hello, sea-orm!");
    let conn = Database::connect("mysql://root:123456@localhost/sea-orm-practice")
    .await
    .expect("Database connection failed");

    //增
    let user_add=user::ActiveModel{  name: Set("nidongde todo!()".to_string()), age: Set(991), ..Default::default() 
    };    

    let _=user_add.save(&conn).await;

    let user=User::find_by_id(2).one(&conn).await;
    println!("{:?}",user);

    let user_filter=user::Entity::find().filter(user::Column::Name.like("yc")).one(&conn).await;
    println!("{:?}",user_filter);

    let user_add:user::ActiveModel=user_filter.unwrap().unwrap().into();

    let _=user_add.save(&conn).await;

}
